const app = getApp() 
var WxParse = require('../../../wxParse/wxParse.js');
Page({
  data: {
    matchmakingAlert: false,
    recommendAlert: false,
    screenWidth: getApp().globalData.windowWidth,
    windowHeight: getApp().globalData.windowHeight,
    safeArea: getApp().globalData.safeArea,
    sdsj: false,
    // sdsjbg: '',
    scsj: false,
    // scsjbg: '',
    cklxfs: 'color: #fff',
    cklxfsbg: 'background: #0cc783;border:solid 1px #0cc783',
    fenxiang: 'color: #fff',
    fenxiangbg: 'background: #0cc783;border:solid 1px #0cc783',
    title: '模组厂绑定COG压排设备 贴合设备低',
    time: '2018-03-14',
    zcMInfo: [],
    gqid: '',
    phonelist: [],
    bannerList1: [],
    videoLink: '',
    currUrl: '',
    showModal: false,
    showModaltel: false,
    LoginUserRankName: '',
    AllLookNum: '',
    HaveLookNum: '',
    NextRankName: '',
    ComAddress: '',
    ComName: '',
    InfoContent: '',
    Mobile: '',
    showModalty: false,
    showModaltyContent: '',
    ADList: [],
    perShow: 10,
    imgUrl: app.data.imgUrl,
    keywordArr: [],
    userInfoDetail: null,
    toView: '',
    isVail: true,
    msg_alert: false,
    isHome: false,
    next_pub_time: '',
    xu_Gqid: '',
    now_show_count: 0,
    timerItem: null,
    reasonsReductionArr: [
      { id: 1, text: '价格过高', isSelected: false },
      { id: 2, text: '不收:废铁', isSelected: false },
      { id: 3, text: '地区太远', isSelected: false },
      { id: 4, text: '处置量太少', isSelected: false },
    ],
    selectCellItemData: {},
    linkAlertStatus: 3,//1确认  3 弹窗
    reasonsSelectIDArr: [],  //
    outpostItem: {},
    showTj: false,
    showGt: false,
    showDj: false,
    contactDisable: false, //商机已被其他会员锁定
    bannerType: 2,
    onlyBannerImg: true,
    current: 0,
    showChangeBannerBtn: false,
    screenHeightAll: 0,
    wxpush: '',
    wxopenid:''
  },
  // 切换banner类型
  changeBannerType: function (e) {
    if (e.currentTarget.dataset.info == '1') {
      this.setData({
        bannerType: 1,
        current: 1
      })
    } else {
      this.setData({
        bannerType: 2,
        current: 0
      })
    }
  },

  //监听轮播图的下标
  monitorCurrent: function (e) {
    let current = e.detail.current;
    this.setData({
      current: current,
      bannerType: this.data.phonelist[current].type
    })
  },

  //联系专员
  contactSpecialist: function () {
    wx.navigateTo({
      url: '../other/otherWeb',
      success: function (res) {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          url: 'https://wap.feijiu.net/towxmini.html?source=scheme',
          pageSrc: 1,
        });
      },
    });
  },
  callPhone: function () {
    wx.makePhoneCall({
      phoneNumber: '15512447985',
    })
  },
  changeMsgAlertStatus: function () {
    this.setData({
      msg_alert: !this.data.msg_alert,
    })
  },
  // 锁定及解锁商机
  handleSdsj: function () {
    if (this.data.contactDisable) {
      return;
    }
    var pages = getCurrentPages();
    if (pages.length >= 2) {
      var before = pages[pages.length - 2];
      if (before.route == 'pages/user/suoding') {
        setTimeout(() => {
          before.onPullDownRefresh()
        }, 100);
      }
    }
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var that = this
    if (!this.data.sdsj) {
      if (app.checkFjLogin()) {
        var api_input = {
          strUID: FjLoginLog.UID,
          strUpw: FjLoginLog.UPwd,
          gqid: this.data.gqid,
          DoAction: 1,
          platform_type: 4
        }
        app.getDaoPost('api/FeijiuApp/Feijiu_Zc_SuoAdd', api_input, function (res) {
          // 服务电话
          that.setData({
            ServiceNum: res.data.ServiceNum
          })
          if (res.data.ZcInfo.ErrNum == 1) {
            var time = new Date(res.data.SuoEndTime).getTime()
            that.countdown(time)
            that.setData({
              sdsj: true,
              // sdsjbg: 'background: #0cc783;border:solid 1px #0cc783'
              // suoEndTime: time
            })
            that.showModalty('商机锁定成功,商机锁定后,只有您一个人可以查看本条消息!')
          } else {
            that.showModalty(res.data.Mess)
          }
        })
        // 刷新锁定状态
        that.getDetail()
      } else {
        wx.navigateTo({ url: '../../pages/login/index' });
      }
    } else {
      let api_input = {
        type: 8,
        gqid: that.data.gqid,
        uid: FjLoginLog.UID,
        uname: FjLoginLog.UName,
        upwd: FjLoginLog.UPwd,
        DoAction: 3,
        // platform_type: 4,
      }
      app.getDaoPost('api/FeijiuApp/Fj_GetMySuo_DelByGqid', api_input, function (res) {
        let resData = JSON.parse(res.data)
        if (res.code == 200) {
          wx.showModal({
            title: '是否解锁本条商机',
            content: `您可锁定 ${resData.AllLockNum} 条商机，剩余锁定条数 ${resData.HaveLockNum} 条`,
            confirmText: '立即解锁',
            confirmColor: '#00B968',
            success(res) {
              let api_input = {
                type: 8,
                gqid: that.data.gqid,
                uid: FjLoginLog.UID,
                uname: FjLoginLog.UName,
                upwd: FjLoginLog.UPwd,
                DoAction: 1,
                // platform_type: 4,
              }
              if (res.confirm) {
                app.getDaoPost('api/FeijiuApp/Fj_GetMySuo_DelByGqid', api_input, function (res) {
                  if (res.code == 200) {
                    if (res.data == 1) {
                      that.showModalty('商机解锁成功')
                      that.setData({
                        sdsj: false,
                        // sdsjbg: ''
                      })
                    } else {
                      that.showModalty('商机解锁失败')
                    }
                  } else {
                    that.showModalty('商机解锁失败')
                  }
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        } else {
          // that.showModalty('商机解锁失败')
        }
      });
    }
  },
  // 收藏商机
  scsj: function () {
    var pages = getCurrentPages();
    if (pages.length > 2) {
      var before = pages[pages.length - 2];
      if (before.route == 'pages/user/myshoucang') {
        setTimeout(() => {
          before.onPullDownRefresh()
        }, 100);
      }
    }
    var that = this
    if (!this.data.scsj) {
      if (app.checkFjLogin()) {
        var FjLoginLog = wx.getStorageSync('FjLoginLog');
        var api_input = {
          strUID: FjLoginLog.UID,
          strUpw: FjLoginLog.UPwd,
          gqid: this.data.gqid,
          DoAction: 1,
          gqType: 2,
          strRSA: app.data.strRSA,
          platform_type: 4
        }
        app.getDaoPost('api/FeijiuApp/Fj_MyZcShouC_Add', api_input, function (res) {
          console.log('res==', res)
          if (res.code == 200) {
            that.setData({
              scsj: true,
              // scsjbg: 'background: #0cc783;border:solid 1px #0cc783'
            })
            that.showModalty('商机收藏成功,可以去个人中心我的收藏去查看全部收藏')
          } else {
            that.showModalty(res.data.message)
          }
        })
      } else {
        wx.navigateTo({ url: '../../pages/login/index' });
      }
    } else {
      var FjLoginLog = wx.getStorageSync('FjLoginLog');
      var api_input = {
        strUID: FjLoginLog.UID,
        gqid: this.data.gqid,
        strRSA: app.data.strRSA,
        gqType: 2
      }
      app.getDaoPostOld('api/FeijiuApp/MyZcShouC_DelByGqid', api_input, function (res) {
        if (res.code == 200) {
          that.setData({
            scsj: false,
            // scsjbg: ''
          })
          that.showModalty('商机解除收藏成功')
        } else {
          that.showModalty('商机解除收藏失败,请确认您是否登录')
        }
      })
    }
  },
  // 查看联系方式
  handleCklxfs: function () {
    var that = this;
    if (that.data.contactDisable) {
      return;
    }
    if (app.checkFjLogin()) {
      var FjLoginLog = wx.getStorageSync('FjLoginLog')
      app.getDaoPost('api/FeijiuApp/Feijiu_GetZcLxfs_Jm', {
        strUID: FjLoginLog.UID,
        strUpw: FjLoginLog.UPwd,
        strGqid: that.data.gqid,
        strRSA: app.data.strRSA,
        platform_type: 4
      }, res => {
        var result = JSON.parse(app.aesDec(res.data.ZcInfo));
        if (result.ErrNum == 111) {
          that.setData({
            LoginUserRankName: result.LoginUserRankName,
            AllLookNum: result.AllLookNum,
            HaveLookNum: result.HaveLookNum,
            NextRankName: result.NextRankName
          })
          that.showDialogBtn();
        } else if (result.ErrNum == 11 || result.ErrNum == 1) {
          let dd = result.InfoContent;
          dd = dd.replaceAll("http://", "https://")
          WxParse.wxParse('dd', 'html', dd, that, 5);
          that.setData({
            userInfoDetail: result,
          })
          that.showModaltel();
        } else {
          that.showModalty('您没有权限查看该联系方式,了解更多请联系客服人员')
        }
      })

      wx.pageScrollTo({
        selector: '.lxfscontent'
      })
      console.log('走走哦啧啧啧啧啧啧')
      return
    } else {
      wx.navigateTo({ url: '../../pages/login/index' });
    }
  },
  // 延长锁定
  handleResetSuo: function () {
    var that = this
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var api_input = {
      uid: FjLoginLog.UID,
      uname: FjLoginLog.UName,
      gqid: this.data.gqid,
    }
    app.getDaoPost('api/FeijiuApp/Feijiu_GetMySuo_Reset_v2024', api_input, function (res) {
      if (res.code == 200) {
        var time = new Date(res.data.SuoEndTime).getTime()
        console.log('time11', time)
        that.countdown(time)
        wx.showToast({
          title: '延长锁定成功',
        })
      }

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.showToast({
      title: "加载中",
      icon: "loading",
    })
    var gqid = options.gqid
    var ishome = options.tools
    if (ishome == 1) {
      var FjLoginLog = wx.getStorageSync('FjLoginLog');
      wx.request({
        url: app.data.api_url2 + "v/vip_mini_detail/",
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        data: {
          'user_id': FjLoginLog.UID,
          'id': gqid,
        },
        method: 'POST',
        success: function (res) {
          if (res.statusCode == 200) {
            if (res.data.code == 200) {
              var next_pub_time = res.data.data.next_pub_time
              var showCount = res.data.data.now_show_count
              that.setData({
                outpostItem: res.data.data,
                next_pub_time: next_pub_time,
                now_show_count: showCount,
                xu_Gqid: res.data.data.id,
              })
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'none'
              })
            }
          }
        }
      });
    }

    if (options.wxpush) {
      this.setData({
        wxpush: options.wxpush
      })
    }

    if (options.wxopenid) {
      this.setData({
        wxopenid: options.wxopenid
      })
    }

    var pages = getCurrentPages();
    var currentPage = pages[pages.length - 1].route + '?gqid=' + gqid//
    this.setData({
      gqid: options.gqid,
      currUrl: currentPage,
      isHome: ishome,
    })
    this.startCountdown()
    this.getDetail()
  },
 //
//  



  //倒计时出发
  startCountdown() {
    const that = this;
    const timerId = setInterval(() => {
      const nowTime = new Date().getTime();
      var leftTime = new Date(that.data.next_pub_time).getTime()
      leftTime = leftTime - nowTime;
      if (leftTime > 0) {
        const countdown = Math.ceil(leftTime / 1000); // 倒计时，单位秒  
        var hour = Math.floor(countdown / 3600)
        hour = String(hour).padStart(2, '0'); // 将数字转换为字符串，并在前面填充零直到长度为2  
        var minute = Math.floor(countdown % 3600 / 60)
        minute = String(minute).padStart(2, '0'); // 将数字转换为字符串，并在前面填充零直到长度为2  
        var second = Math.floor(countdown % 3600 % 60)
        second = String(second).padStart(2, '0'); // 将数字转换为字符串，并在前面填充零直到长度为2  
        that.setData({
          hour: hour, minute: minute, second: second,
          isCountdown: true
        })
      } else {
        clearInterval(timerId); // 清除定时器  
        that.setData({ hour: 0, minute: 0, second: 0, isCountdown: false }); // 从列表中移除已结束的项  
      }
    }, 1000);
    this.timerItem = timerId;
  },

  // 倒计时
  countdown: function (endTime) {
    var that = this
    // const countDownElement = document.getElementById('countdown');
    // var timer;
    if (that.data.timer) {
      clearInterval(that.data.timer)
    }
    that.setData({
      timer: setInterval(function () {
        const now = new Date().getTime();
        const distance = endTime - now;
        if (distance < 0) {
          clearInterval(that.data.timer);
          // countDownElement.innerHTML = "倒计时结束";
          return;
        }

        const days = Math.floor(distance / (1000 * 60 * 60 * 24));
        const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        const seconds = Math.floor((distance % (1000 * 60)) / 1000);
        // console.log('day', days)
        // console.log('hour', hours)
        // console.log('minutes', minutes)
        that.setData({
          days: days,
          hours: hours,
          minutes: minutes,
          seconds: seconds
        })
        // return days + "天 " + hours + "小时 " + minutes + "分钟";
      }, 1000)
    })
  },

  // 获取详情
  getDetail: function () {
    var that = this
    var gqid = that.data.gqid

    var FjLoginLog = wx.getStorageSync('FjLoginLog')
    if (FjLoginLog.UID) {
      var api_input = {
        strID: gqid,
        longUID: FjLoginLog.UID
      }
      that.setData({
        islogInActive: true
      })
    } else {
      var api_input = {
        strID: gqid
      }
      that.setData({
        islogInActive: false
      })
    }

    if (this.data.wxpush && this.data.wxpush != undefined && this.data.wxpush != '') {
      api_input['wxpush'] = this.data.wxpush
    }
    if (this.data.wxopenid && this.data.wxopenid != undefined && this.data.wxopenid != '') {
      api_input['wxopenid'] = this.data.wxopenid
    }
    // console.log('~~~~获取资产~~~~~~~~~~', parame)

    app.getDaoPost('api/FeijiuApp/Post_FJ_GetZcMInfo', api_input, function (res) {
      /** 
       * IsSuo=1自己锁的
       * ShId=4  &&  IsSuo=0 别人锁的
       * IsSuo=0 没有锁定
       * */
      console.log('res===', res)
      if (res.data.IsSuo == '0' && res.data.ZcInfo.ShId == '4') {
        that.setData({
          contactDisable: true
        })
      }
      if (res.data.IsSuo == '1') {
        var time = new Date(res.data.SuoEndTime).getTime()
        var newTime = that.countdown(time)
        that.setData({
          sdsj: true,
          SuoEndTime: newTime
        })
      }
      if (res.code == 200) {
        res.data.ZcInfo.FbDate = res.data.ZcInfo.FbDate.replace('T', " ")
        res.data.ZcInfo.dqsj = res.data.ZcInfo.FbDate.substr(0, 10)
        res.data.ZcInfo.FbDate = res.data.ZcInfo.FbDate.substr(0, 10)
        var lastString = res.data.ZcInfo.KeyWord.substr(res.data.ZcInfo.KeyWord.length - 1, 1);
        if (lastString == ',') {
          res.data.ZcInfo.KeyWord = res.data.ZcInfo.KeyWord.substr(0, res.data.ZcInfo.KeyWord.length - 1);
        }
        var keywordarr;
        if (res.data.ZcInfo.KeyWord != "") {
          keywordarr = res.data.ZcInfo.KeyWord.split(',')
        }
        var now = new Date()
        var effectiveDate = new Date(res.data.effectiveDate)
        var nowTimeintvalue = now.getTime()
        var effectiveTimeIntvalue = effectiveDate.getTime()
        var isVail = true;
        if (res.data.effectiveDate == '长期有效') {
          isVail = true;
        } else {
          isVail = nowTimeintvalue <= effectiveTimeIntvalue
        }
        var phoneList = res.data.ZcInfo.Photo ? res.data.ZcInfo.Photo.split('|') : []
        var videoList = res.data.ZcInfo.video
        phoneList = phoneList.map(item => {
          return { url: item, type: 1 }
        });
        if (videoList) {
          phoneList = [{ url: videoList, type: 2 }, ...phoneList]

        }
        // 判断是否显示视频图片按钮
        if (res.data.ZcInfo.Photo && res.data.ZcInfo.video) {
          that.setData({
            showChangeBannerBtn: true
          })
        } else {
          that.setData({
            showChangeBannerBtn: false
          })
        }
        that.setData({
          zcMInfo: res.data,
          keywordArr: keywordarr,
          phonelist: phoneList,
          isVail: isVail
        })
        if (res.data.IsSC == 1) {
          that.setData({
            scsj: true,
            // scsjbg: 'background: #0cc783;border:solid 1px #0cc783'
          })
        } else {
          that.setData({
            scsj: false,
            // scsjbg: ''
          })
        }
        if (res.data.IsSuo == 1) {
          that.setData({
            sdsj: true,
            // sdsjbg: 'background: #0cc783;border:solid 1px #0cc783'
          })
        } else {
          that.setData({
            sdsj: false,
            // sdsjbg: ''
          })
        }
        // 标题前面标签
        if (res.data.ZcInfo.Title.indexOf('个体') !== -1) {
          that.setData({
            showGt: true,
            showDj: false,
            showTj: false
          })
        }
        if (res.data.ZcInfo.Title.indexOf('独家') !== -1) {
          that.setData({
            showDj: true,
            showGt: false,
            showTj: false
          })
        }
        if (res.data.ZcInfo.TjId > 0) {
          that.setData({
            showTj: true,
            showDj: false,
            showGt: false
          })
        }

      }
    })
  },
  /**
    * 生命周期函数--监听页面初次渲染完成
    */
  onReady: function () {
    var that = this
    setTimeout(() => {
      let query = wx.createSelectorQuery();
      query.select('.zccz_detailed_foot').boundingClientRect(rect => {
        console.log('zccz_detailed_foot', JSON.stringify(rect))
        that.setData({
          screenHeightAll: rect.top
        })
      }).exec();
      // 如果有bottom_tip，那scrollView高度就是整个屏幕高度-bottom_tip高度
      // 其实就是bottom_tip距离顶部的距离rectT.top
      // 如果没有bottom_tip，那就是执行上面zccz_detailed_foot的代码
      query.select('.bottom_tip').boundingClientRect(rectT => {
        console.log('bottom_tip', JSON.stringify(rectT))
        if (rectT) {
          that.setData({
            screenHeightAll: rectT.top
          })
        }
      }).exec();

    }, 300);




  },
  toF5() {
    this.onShow()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDetail()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearInterval(this.timerItem); // 清除定时器  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    var that = this;
    var shareObj = {
      title: that.data.zcMInfo.ZcInfo.Title,
      path: '/packageA/pages/zichanchuzhi/detailed?gqid=' + this.data.gqid,
      imgUrl: '',
    };
    if (options.from == 'button') {
      shareObj.path = '/packageA/pages/zichanchuzhi/detailed?gqid=' + this.data.gqid;
    }
    return shareObj;
  },
  /**
   * 弹窗
   */
  showDialogBtn: function () {
    this.setData({
      showModal: true
    })
  },
  preventTouchMove: function () {

  },
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  onCancel: function () {
    this.hideModal();
  },
  phoneLinkClick: function () {

    this.hideModal();
    this.handleCklxfs()
  },
  onConfirm: function () {
    this.hideModal();
    wx.showToast({
      title: "加载中",
      icon: "loading",
    })
    var that = this
    var FjLoginLog = wx.getStorageSync('FjLoginLog')
    app.getDaoPost('api/FeijiuApp/Feijiu_GetZcLxfsInfo_Jm', {
      strUID: FjLoginLog.UID,
      strUpw: FjLoginLog.UPwd,
      strGqid: that.data.gqid,
      strRSA: app.data.strRSA,
      platform_type: 4
    }, res => {
      var result = JSON.parse(app.aesDec(res.data.ZcInfo));
      console.log('result11', result)
      wx.hideToast()
      if (result.ErrNum == 1) {
        let dd = result.InfoContent;
        dd = dd.replaceAll("http://", "https://")
        WxParse.wxParse('dd', 'html', dd, that, 5);
        that.setData({
          userInfoDetail: result,
        })
        console.log('userInfoDetail==', that.data.userInfoDetail)
        that.showModaltel();
      }
    })
    wx.pageScrollTo({
      selector: '.lxfscontent'
    })


    return
    wx.request({
      url: app.data.api_url + "api/FeijiuApp/GetZcLxfsInfo_Jm?strUID=" + FjLoginLog.UID + "&strUpw=" + FjLoginLog.UPwd + "&strGqid=" + that.data.gqid + "&strRSA=" + app.data.strRSA,
      success: function (res) {
        var result = JSON.parse(app.aesDec(res.data.data));
        wx.hideToast()
        if (result.ErrNum == 1) {
          that.setData({
            ComAddress: result.ComAddress,
            ComName: result.ComName,
            InfoContent: result.InfoContent.replace(/<\/?.+?>/g, ""),
            Mobile: result.Mobile,
          })
          that.showModaltel();
        }
      }
    })
  },
  showModaltel: function () {
    this.setData({
      toView: 'userInfoDetail'
    })
  },
  onCanceltel: function () {
    this.setData({
      showModaltel: false
    })
  },

  onCancelty: function () {
    this.setData({
      showModalty: false
    })
  },
  showModalty: function (tishi) {
    this.setData({
      showModalty: true,
      showModaltyContent: tishi
    })
  },
  fuwudianhua: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.ServiceNum
    })
  },
  callMobile: function () {
    if (this.data.userInfoDetail.Mobile != '暂无' && this.data.userInfoDetail.Mobile.length) {
      wx.makePhoneCall({
        phoneNumber: this.data.userInfoDetail.Mobile,
      })
    }
  },
  ComPhone: function () {
    if (this.data.userInfoDetail.ComPhone != '暂无' && this.data.userInfoDetail.ComPhone.length) {
      wx.makePhoneCall({
        phoneNumber: this.data.userInfoDetail.ComPhone,
      })
    }
  },
  otherwaysClick: function () {
    if (this.data.userInfoDetail.otherways != '暂无' && this.data.userInfoDetail.otherways.length) {
      wx.setClipboardData({
        data: this.data.userInfoDetail.otherways, // 需要复制的文本  
        success: function () {
          wx.showToast({
            title: '复制成功',
            icon: 'none'
          })
        }
      });
    }
  },
  callClick: function (params) {
    if (this.data.userInfoDetail.Mobile.length) {
      wx.makePhoneCall({
        phoneNumber: this.data.userInfoDetail.Mobile,
      })
    }
    if (this.data.userInfoDetail.ComPhone.length) {
      wx.makePhoneCall({
        phoneNumber: this.data.userInfoDetail.ComPhone,
      })
    }
    if (this.data.userInfoDetail.otherways.length) {
      wx.setClipboardData({
        data: this.data.userInfoDetail.otherways, // 需要复制的文本  
        success: function () {
          wx.showToast({
            title: '复制成功',
            icon: 'none'
          })
        }
      });
    }
  },
  //电话联系
  telephoneContact(e) {
    var that = this;
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    wx.request({
      url: app.data.api_url2 + "v/vip_get_contact/",
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      data: {
        'user_id': FjLoginLog.UID,
        'id': that.data.xu_Gqid,
        'action': 3
      },
      method: 'POST',
      success: function (res) { }
    });
    this.handleCklxfs()
  },
  //减少推荐理由事件
  reasonClick(e) {
    this.data.reasonsReductionArr.map(item => {
      item.isSelected = false
    })
    const index = e.currentTarget.dataset.index;
    const item = e.currentTarget.dataset.item
    this.data.reasonsReductionArr[index].isSelected = true
    this.data.reasonsSelectIDArr = [item.id]
    this.setData({
      reasonsReductionArr: this.data.reasonsReductionArr,
      reasonsSelectIDArr: this.data.reasonsSelectIDArr
    })
    /*多选逻辑
    const index = e.currentTarget.dataset.index;
    const item = e.currentTarget.dataset.item
    var updatedList = this.data.reasonsSelectIDArr
    this.data.reasonsReductionArr[index].isSelected = !item.isSelected
    if(this.data.reasonsReductionArr[index].isSelected){
      this.data.reasonsSelectIDArr.push(item.id)
    }else{
      updatedList = this.data.reasonsSelectIDArr.filter(listItem => listItem !== item.id);
    }
    this.setData({
      reasonsReductionArr:this.data.reasonsReductionArr,
      reasonsSelectIDArr:updatedList
    })
    */
  },
  //提交减少推荐理由
  submitRecommendClick(e) {
    var itemId = this.data.selectCellItemData.id
    if (this.data.reasonsSelectIDArr.length <= 0) {
      wx.showToast({
        title: '请选择减少推荐理由',
        icon: 'none'
      })
    } else {
      var that = this;
      var FjLoginLog = wx.getStorageSync('FjLoginLog');
      var choice = that.data.reasonsSelectIDArr[0]
      wx.request({
        url: app.data.api_url2 + "v/vip_mini_low/",
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        data: {
          'user_id': FjLoginLog.UID,
          'id': itemId,
          'choice': choice
        },
        method: 'POST',
        success: function (res) {
          if (res.statusCode == 200) {
            if (res.data.code == 200) {
              that.setData({
                recommendAlert: false
              })
              wx.setStorageSync('zcRecommendId', itemId);
              wx.navigateBack()
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'none'
              })
            }
          }
        }
      });
    }
  },
  //人工撮合
  matchmakingBtnClick(e) {
    if (this.data.matchmakingAlert) {
      this.setData({ matchmakingAlert: !this.data.matchmakingAlert })
      return
    }
    var itemId = this.data.xu_Gqid
    var that = this;
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    wx.request({
      url: app.data.api_url2 + "v/vip_mini_film/",
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      data: {
        'user_id': FjLoginLog.UID,
        'id': itemId,
      },
      method: 'POST',
      success: function (res) {
        if (res.statusCode == 200) {
          if (res.data.code == 200) {
            that.setData({ matchmakingAlert: !that.data.matchmakingAlert })
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        }
      }
    });
  },
  //减少推荐
  recommendBtnClick(event) {
    var item = this.data.outpostItem;
    if (item) {
      var addressArr = item.address.split(" ")
      var categoryArr = item.cate_name.split(" ")
      this.data.reasonsReductionArr[1].text = '不收:' + categoryArr[categoryArr.length - 1]
      this.data.reasonsReductionArr[2].text = '地区太远:' + addressArr[addressArr.length - 1]
      this.setData({
        reasonsReductionArr: this.data.reasonsReductionArr
      })
    }
    this.setData({ recommendAlert: !this.data.recommendAlert, selectCellItemData: item })
  },
  //修改回收偏好
  changePreference: function () {
    wx.navigateTo({
      url: '/packageB/pages/recyclingPreference/preference',
    });
  },
  releaseClick: function () {
    if (app.checkFjLogin()) {
      wx.navigateTo({
        url: '/packageB/pages/quickRelease/quickIndex/quickIndex',
      })
    }
  },
  onPreviewImage: function (event) {
    var index = event.currentTarget.dataset.index;
    var lists = this.data.phonelist.map(i => i.url);
    var item = lists[index];
    wx.previewImage({
      urls: lists,
      current: item,
      fail: function () {
        wx.showToast({ title: '预览图片失败', icon: 'none' });
      },
    });
  },
  //图片加载失败时
  errorFunction: function (event) {
    var index = event.currentTarget.dataset.index
    var img = 'zcMInfo.Xgzc.ds[' + index + '].photo'
    this.setData({
      [img]: 'https://style.feijiu.net/images/app/ggnoimg.png'
    })
  },
  // 点击更多
  moreClick(e) {
      console.log(this.data.zcMInfo.Cplb)
      console.log(this.data.zcMInfo.LastCIndex)
      wx.navigateTo({
        url: `/packageA/pages/zichanchuzhi/index?className=${this.data.zcMInfo.Cplb}&classID=${this.data.zcMInfo.LastCIndex}`,
      })
      
  }
})